<?php

//用户登陆
include_once '../../library/config.php';
include_once '../../model/userlist.php';


$entity = new UserList();
$entity->request();

$list = new UserList();
try {

    if (!preg_match("/^1[34578]\d{9}$/", $entity['account'])) {
        throw new Exception("101"); //匹配手机号格式
    }
    if (!preg_match("/(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{6,12}/", $entity['pwd'])) {
        throw new Exception("102"); //匹配密码格式
    }
    if (!$list->select("pwd,myid,nickname,sex,shengid,schoolid,grade")->where("account=" . $entity['account'])->get_first_rows()) {
        throw new Exception("104"); //帐号是否已注册
    }
    $pwd = md5($entity['account'] . $entity['pwd']);
    if ($pwd != $list['pwd']) {
        throw new Exception("105");
    }
    $list->keyvalue("usertoken", md5($entity['account'] . $entity['myid']));
} catch (Exception $ex) {
    $entity->rsscode($ex);
}
$list->toKeyValue("account",$entity['account']);
$list->remove(array('pwd')); //返回值删除密码
echo $list->toJson();
